package testdatagenerator;

import java.awt.Dimension;

import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;


public class MyMenu extends JPanel {
	private static final long serialVersionUID = 1L;
	private int width, height;
	private JScrollPane pane;
	private DefaultListModel options;
	private JList list;
	public Object getSelected(){
		return list.getSelectedValue();
	}
	public void removeItem(Object item){
		options.removeElement(item);
		refresh();
	}
	public void addItem(Object item){
		options.addElement(item);
		refresh();
	}
    @Override
	public void setEnabled(boolean enabled){
		pane.setEnabled(enabled);
	}
	public void refresh(){
		if (pane!=null){
			this.remove(pane);
		}	
		list = new JList(options);
		list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
		list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
		pane = new JScrollPane(list);
		this.add(pane);
		this.SetSize(width, height);
		this.updateUI();
	}
	public void SetSize(int x, int y){
		width = x; 
		height = y;
		pane.setSize(x, y);
		Dimension size = new Dimension(x, y);
		pane.setPreferredSize(size);
		this.setSize(size);
		this.setPreferredSize(size);
	}
	public MyMenu(){
		options = new DefaultListModel();
		pane = null;
		refresh();
		setSize(300, 300);
	}
}
